<?php
error_reporting(E_ALL);
require_once "validator.php";

V::init(array(
	"user_name" => "Your name::req",
	"user_pass" => "Your pasword::req isPass passConf=user_pass_conf",
	"user_pass_conf" => "Password confirmation::req",
	"user_email" => "Email::req isEmail",
	"user_code" => "Code::isInt min=1000 max=9999",
	"user_bd" => "Birthday::isDate",
	"cc_type" => "Credit card::isCC ccNum=cc_num ccM=cc_exp_month ccY=cc_exp_year",
	"cc_num" => "Credit card number::null", // title only
	"cc_exp_month" => "Expiration month::null",
	"cc_exp_year" => "Expiration year::null"
));

if (isset($_POST['save'])) {
	if (V::success()) {
		$msg = "Data saved!";
	} else {
		$err = V::getError();
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title>Test class Validator</title>
<script type="text/javascript" src="validator.js"></script>
</head>

<body>
<?php
	if (isset($msg)) echo '<p style="color:#009966">'.$msg.'</p>';
	if (isset($err)) echo '<p style="color: red">'.$err.'</p>';
?>
<form id="form1" name="form1" method="post" action="">
<table border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td>Name</td>
<td><input name="user_name" type="text" id="user_name" value="<?php if (isset($_POST['user_name'])) echo $_POST['user_name']; ?>" /></td>
</tr>
<tr>
<td>Email</td>
<td><input name="user_email" type="text" id="user_email" value="<?php if (isset($_POST['user_email'])) echo $_POST['user_email']; ?>" /></td>
</tr>
<tr>
<td>Pass</td>
<td><input name="user_pass" type="text" id="user_pass" value="<?php if (isset($_POST['user_pass'])) echo $_POST['user_pass']; ?>" /></td>
</tr>
<tr>
<td>Conf</td>
<td><input name="user_pass_conf" type="text" id="user_pass_conf" value="<?php if (isset($_POST['user_pass_conf'])) echo $_POST['user_pass_conf']; ?>" /></td>
</tr>
<tr>
<td>Code </td>
<td><input name="user_code" type="text" id="user_code" value="<?php if (isset($_POST['user_code'])) echo $_POST['user_code']; ?>" /></td>
</tr>
<tr>
<td>Birthday</td>
<td><input name="user_bd" type="text" id="user_bd" value="<?php if (isset($_POST['user_bd'])) echo $_POST['user_bd']; ?>" /></td>
</tr>
<tr>
  <td>CCType</td>
  <td><select name="cc_type" id="cc_type">
    <option value="V" selected="selected">Visa</option>
    <option value="M">Mastercard</option>
  </select>
  </td>
</tr>
<tr>
  <td>CCNum</td>
  <td><input name="cc_num" type="text" id="cc_num" value="<?php if (isset($_POST['cc_num'])) echo $_POST['cc_num']; ?>" /></td>
</tr>
<tr>
  <td>CCExp</td>
  <td><select name="cc_exp_month" id="cc_exp_month">
    <option value="08" selected="selected">aug</option>
    <option value="09">sep</option>
    <option value="10">oct</option>
    <option value="11">nov</option>
  </select>
  /
  <select name="cc_exp_year" id="cc_exp_year">
    <option value="2007" selected="selected">2007</option>
    <option value="2008">2008</option>
  </select>
  </td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="button" id="button" value="Submit" />
<input name="save" type="hidden" id="save" value="1" /></td>
</tr>
</table>
</form>
<hr/>
<?php echo V::jsvalidation('form1'); ?>

</body>
</html>
